package com.example.work2

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView


class MessageAdapter(val msg: ArrayList<Msg>) : RecyclerView.Adapter<MessageAdapter.ViewHolder>()  {
    inner class ViewHolder(itemView: View):RecyclerView.ViewHolder(itemView) {
        val touxiang=itemView.findViewById<ImageView>(R.id.pic1)
        val name=itemView.findViewById<TextView>(R.id.name1)
        val content=itemView.findViewById<TextView>(R.id.content1)
        val time =itemView.findViewById<TextView>(R.id.time1)
    }
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.message_view,parent,false)
        val holder = ViewHolder(view)
        return holder
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val msg=msg[position]
        holder.touxiang.setImageResource(msg.imageId)
        holder.name.text= msg.name
        holder.content.text=msg.content
        holder.time.text=msg.time
    }
    override fun getItemCount() = msg.size

}